/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package converters;

import com.mycompany.psc.ejb.ReportableItemsManager;
import com.mycompany.psc.entities.Aluminium;
import javax.ejb.EJB;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

/**
 *
 * @author ahmed
 */
@FacesConverter(forClass = Aluminium.class,value = "aluminiumConverter")
public class AlluminiumConverter implements Converter{
    @EJB
    ReportableItemsManager rm;

    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        return rm.getAluminiumResourceByName(value);
    }

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
       if(value instanceof Aluminium){
            Aluminium u=(Aluminium)value;
    
        return u.getTitle();
        }else{
            return "no value";
        }
    }
}
